import { request } from "@/utils/service"

export type RowMeta = {
  id: number;
  name: string;
  jobTitle: number | string;
  status: number
  /** vxe-table 自动添加上去的属性 */
  _VXE_ID?: string;
};

export type PeopleResponseData = RowMeta & {
  updatedAt: string;
};


export type PeopleTableData = ApiResponseData<{
  list: PeopleResponseData[]
  total: number
}>

interface searchParams {
  /** 当前页码 */
  currentPage: number
  /** 查询条数 */
  size: number
  name?: string
}

// 添加人员
export function addPeopleApi(data: RowMeta) {
  return request<ApiResponseData<null>>({
    url: "/customer/people",
    method: "post",
    data
  })
}

// 编辑人员
export function updatePeopleApi(data: RowMeta) {
  return request<ApiResponseData<PeopleResponseData>>({
    url: "/customer/people",
    method: "put",
    data
  })
}

// 获取人员
export function getPeopleApi(params: searchParams) {
  return request<PeopleTableData>({
    url: "/customer/people",
    method: "get",
    params
  })
}

export function getAllPeopleApi() {
  return request<PeopleTableData>({
    url: "/customer/people",
    method: "get",
  })
}

/** 删 */
export function deletePeopleApi(id: number) {
  return request({
    url: `customer/people/${id}`,
    method: "delete"
  })
}
